<template>
  <div style="width: 100%;height:100%;padding:5px;">
    <rx-fit >
        <div class="btnContainer" style="padding-top:6px;">
            <a-button icon="save" @click="saveData"  type="primary" size="small">{{i18n('list.saveData','保存数据')}}</a-button>
        </div>
        <rx-fit class="BpmAtabpane">
            <rx-forms ref="rxForms"></rx-forms>
        </rx-fit>
    </rx-fit>
    <!-- 流程实例日志 -->
    <bpm-inst-logs :instId="instId" :log-show.sync="logShow" />
    <!--流程实例消息-->
    <bpm-inst-msgs :instId="instId" :msg-show.sync="msgShow"/>
    <!--审批历史-->
    <bpm-check-history  :inst-id="instId"  :historyShow.sync="historyShow" />
  </div>
</template>

<script>
  import {BaseForm,RxDialog,Util,RxFit, Dialog} from '@lowcode/jpaas-common-lib';
  import BpmInstMsgs from "./BpmInstMsgs"
  import BpmInstLogs from "./BpmInstLogs";
  import BpmInstApi from '@/api/bpm/core/bpmInst'
  import FormPcApi from '@/api/form/core/formPc'
  import BpmImageView from "../comps/BpmImageView";
  import RxForms from "./RxForms";
  import BpmCheckHistory from "./BpmCheckHistory";
  import formbase from '@/api/formbase';
  import BpmDefApi from "@/api/bpm/core/bpmDef";
  import BpmNodeJump from './BpmNodeJump.vue';
  import BpmInstVars from './component/BpmInstVars.vue';
  import BpmInstUsers from './component/BpmInstUsers';
  import userState from "@/assets/js/userState";


  export default {
    name: "BpmInstFormOperat",
    components:{
      RxDialog,
      RxFit,
      RxForms,
      BpmInstMsgs,
      BpmInstLogs,
      BpmImageView,
      BpmCheckHistory,
      Dialog,
      BpmInstVars,
      BpmInstUsers
    },
    mixins:[formbase,userState],
    props:{
      instId:{
        type:String,
        required:true
      },
      backNodeId:{//在流程明细中进行回退时指定的目标节点
        type:String,
        required:false
      },
      layerid: String,
      lydata: Object,
      destroy:Function
    },
    data(){
      return {
        historyShow:false,
        logShow:false,
        msgShow:false,
        bpmInstDetail:{},
        backBtnLoading:false,//撤回按钮加载状态
        actInstId:"",
        defId:"",
      }
    },
    created() {
      this.loadDetail();
    },
    methods: {
      i18n(name,text,key){
          return this.$ti18(name,text,"BpmInstFormOperat",key);
      },
      subCloseWindow(action){
        Util.closeWindow(this,action);
      },
      showCheckHistory(){
        this.historyShow=true;
      },
      showBpmInstLog(){
        this.logShow=true;
      },
      showMsg(){
        this.msgShow=true;
      },
      //修改流程定义配置
      modifyProcess(){
        let url=BpmDefApi.designBaseUrl+'?defId=' + this.bpmInstDetail.bpmInst.defId;
        window.open(url);
      },
      loadDetail() {
        let self = this;
        if(!this.instId){
          this.instId=this.$route.params.instId;
        }
        BpmInstApi.getInstDetailForInterpose(this.instId).then(res => {
          this.bpmInstDetail=res;
            var curUser=this.user;
          this.actInstId=this.bpmInstDetail.bpmInst.actInstId;
          this.defId=this.bpmInstDetail.bpmInst.defId;
          let contextData={
            instId:self.instId,
            tenantId: curUser.tenantId,
            tenantLabel:curUser.tenantLabel,
            opinionHistorys:res.bpmCheckHistories
          };

          self.$refs.rxForms.setData(res.formData.data,false,contextData);
        })
      },
      saveData(){
          var self_=this;
          this.$confirm({
              title: this.$ti18('rxMsa.tipsInfo','提示信息'),
              content: self_.i18n('msa.saveTips','确认保存表单数据吗?'),
              okText: this.$ti18('rxForm.ackBtn','确认'),
              cancelText: this.$ti18('rxForm.cancelBtn','取消'),
              zIndex:20000,
              onOk() {
                  var json=self_.$refs.rxForms.getData();
                  let appId=self_.bpmInstDetail.bpmInst.appId;
                  FormPcApi.saveFormDataDirect(json,appId);
                  Util.close(self_, 'ok');
              }
          });
      },
      formPrint(){
          var self_=this;
          this.$refs.rxForms.setReadonly(true);
          setTimeout(function () {
              self_.printForm();
              setTimeout(function () {
                      self_.$refs.rxForms.setReadonly(false);},
                  500);
          },300);

      }
    }
  }
</script>

<style scoped>
.BpmAtabpane{
  height: calc(100% - 35px) !important;
}
  .btnContainer{
    padding: 2px 10px 2px 0px ;
    width: 100%;
    text-align: right;

  }
</style>